home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
-
- Printing.c
-
- This file contains the printing code for the QuickDraw GX unaware
- sample, "Simple Sample."
-
- Additional info can be found in the related develop #19 article,
- "Adding QuickDraw GX Printing to QuickDraw Applications."
-
- Dave Hersey, Apple Developer Technical Support.
-
- ——————— Edit Trail ———————
-
- coughed up: 1/22/94 - dmh
- cleaned up for 2nd draft of develop article: 3/10/94 - dmh
- cleaned up for final: 4/14/94 - dmh
-
- *********************************************************************/
-
- #include "Simple Sample.h"
-
-
- /************************************************************
- MyPrintDocument - This routine displays the Print dialog,
- and then prints the document.
-
- *************************************************************/
-
- OSErr MyPrintDocument(MyDocumentPtr whichDocument)
- {
- OSErr err = noErr;
-
- /*
- Open the printer driver, and put up the Print dialog. If
- the user clicks the Print button, print the document.
- */
- PrOpen();
-
- PrValidate(whichDocument->documentPrintHdl);
-
- if (PrJobDialog(whichDocument->documentPrintHdl))
- err = MyPrintLoop(whichDocument);
-
- PrClose();
-
- return err;
- }
-
-
- /************************************************************
- MyPrintLoop - This is our app's print loop.
-
- *************************************************************/
-
- OSErr MyPrintLoop(MyDocumentPtr whichDocument)
- {
- OSErr err = noErr;
- THPrint hPrint;
- TPPrPort printPort;
- TPrStatus theStatus;
- short copy, pg, iFstPage, iLstPage, oldCurPage;
-
- hPrint = whichDocument->documentPrintHdl;
- oldCurPage = whichDocument->curPage;
-
- iFstPage = (*hPrint)->prJob.iFstPage;
- if (iFstPage < 1)
- iFstPage = 1;
-
- iLstPage = (*hPrint)->prJob.iLstPage;
- if (iLstPage > whichDocument->numPages)
- iLstPage = whichDocument->numPages;
-
- (*hPrint)->prJob.iFstPage = 1;
- (*hPrint)->prJob.iLstPage = 9999;
-
- /*
- Loop for the number of copies we need to make, opening a
- document and a page for each.
- */
- for (copy = 1; !err && (copy <= (*hPrint)->prJob.iCopies); copy++)
- {
- printPort = PrOpenDoc(hPrint, nil, nil);
-
- if (!(err = PrError()))
- for (pg = iFstPage; pg <= iLstPage; pg++)
- {
- PrOpenPage(printPort, nil);
-
- whichDocument->curPage = pg;
- MyDrawContents(whichDocument->documentWindow);
-
- PrClosePage(printPort);
- }
-
- PrCloseDoc(printPort);
- }
-
- // When finished printing, call PrPicFile (if necessary).
-
- if (!err) err = PrError();
-
- if (!err && ((*hPrint)->prJob.bJDocLoop == bSpoolLoop))
- PrPicFile(hPrint, nil, nil, nil, &theStatus);
-
- whichDocument->curPage = oldCurPage;
-
- return err;
- }
-
-
- /************************************************************
- MyDoPageSetup - This routine handles the "Page Setup"
- dialog.
-
- *************************************************************/
-
- Boolean MyDoPageSetup(MyDocumentPtr whichDocument)
- {
- Boolean result;
-
- PrOpen();
- PrValidate(whichDocument->documentPrintHdl);
- result = PrStlDialog(whichDocument->documentPrintHdl);
- PrClose();
-
- return result;
- }
-
-
- /************************************************************
- MyRepaginateDoc - This routine handles repagination of our
- document.
-
- *************************************************************/
-
- void MyRepaginateDoc(MyDocumentPtr whichDocument)
- {
- long pageNum;
- Rect repaginateRect;
-
- for (pageNum = 1; pageNum <= whichDocument->numPages; pageNum++)
- {
-
- // Repaginate our document using the print record's rPage.
-
- repaginateRect = (*whichDocument->documentPrintHdl)->prInfo.rPage;
-
- /*
- Repaginate the document based on our printable area.
- .
- .
- .
- */
-
- }
- }
-